<?php 
if (!defined('BASEPATH')) exit('No direct script access allowed');

class My_functions {

     public function __construct() {
        //parent::__construct();
        $this->obj = &get_instance();
    }
    
    
   //$CI=$this->obj;
    
    
    //get latest login id
    //return latest login id
    public function getLatestLoginId()
	{
		$CI = $this->obj;
      
        $query = $CI->db->query('SELECT MAX(login.id) AS login_id FROM login');

         if ($query->num_rows() > 0)
        {
          foreach ($query->result() as $row)
        {
            return $row->login_id;
        }
        
        }
        else
        {
            return null;
        }
        
	}
	
	//get login id of staff
	public function getStaffLoginId($staff_id)
	{
		$CI = $this->obj;
      
         $CI->db->select('staff.login_id');
		$CI->db->where('staff.id',$staff_id);

		$query = $CI->db->get('staff');

         if ($query->num_rows() > 0)
        {
          foreach ($query->result() as $row)
        {
            return $row->login_id;
        }
        
        }
        else
        {
            return null;
        }
        
	}
	
	//to check if the staff name is still available to be assigned to login
	public function checkAllStaffHasNoAcess()
	{
		$CI = $this->obj;
		
		$CI->db->select('*,staff.name as staff_name,department.name as dep_name,
			staff.id as staff_id
			');
			$CI->db->from('staff');
			
			$CI->db->join('department', 'staff.department_id = department.id');
			
			$CI->db->order_by("staff.id", "asc"); 
			$CI->db->where('staff.login_id',NULL);
		
			$query = $CI->db->get();
			
			if($query -> num_rows() > 0) {
				return true;
				
		}
			else {
				return false;
			}
	}
}
	